package cn.z2huo.demo.spring.quartz.quartz;

import cn.z2huo.demo.spring.quartz.quartz.job.TestJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 *
 * @author z2huo
 */
@Configuration
public class QuartzConfig {

    @Bean("testJobDetail")
    public JobDetail testJobDetail() {
        return JobBuilder.newJob(TestJob.class)
                .withIdentity("testJob")
                .withDescription("测试定时任务")
                .storeDurably()
                .requestRecovery()
                .build();
    }

    @Bean
    public Trigger testJobTrigger(@Qualifier("testJobDetail") JobDetail jobDetail) {
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail)
                .withIdentity("testJobTrigger", "demo-spring-quartz")
                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(10))
//                .withSchedule(CronScheduleBuilder.cronSchedule("0/10 * * * * ? "))
                .startNow()
                .build();
    }

}
